package com.yuke.cloud.service.smc.service.impl;

import com.yuke.cloud.common.core.support.BaseService;
import com.yuke.cloud.service.api.wmc.dto.StorageSpecInfoDto;
import com.yuke.cloud.service.api.wmc.service.WmcStorageFeignApi;
import com.yuke.cloud.service.smc.dao.ShopRecommendMapper;
import com.yuke.cloud.service.smc.entity.ShopRecommend;
import com.yuke.cloud.service.smc.service.ShopRecommendService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;


/**
 * Created by zn on 2021/03/22.
 */
@Service
@Slf4j
@Transactional
public class ShopRecommendServiceImpl extends BaseService<ShopRecommend> implements ShopRecommendService {
    @Resource
    private ShopRecommendMapper shopRecommendMapper;
    @Resource
    private WmcStorageFeignApi wmcFeignApi;


    @Override
    public List<ShopRecommend> selectShopRecommendList(ShopRecommend shopRecommend){
        //return shopRecommendMapper.selectShopRecommendList(shopRecommend);
        return shopRecommendMapper.select(shopRecommend);
    }

    @Override
    public List<StorageSpecInfoDto> getListByCondition(ShopRecommend goods) {
        List<StorageSpecInfoDto> prodSpecInfoDtos = new ArrayList<>();
        List<ShopRecommend> shopRecommendList = shopRecommendMapper.getListByCondition(goods);
        if (shopRecommendList.size() == 0) {
            return prodSpecInfoDtos;
        }

        List<Long> specIds = shopRecommendList.stream().map(ShopRecommend::getSpecId).collect(Collectors.toList());
        System.out.println(specIds);
        System.out.println(goods.getShopId());
        prodSpecInfoDtos = wmcFeignApi.getStorageInfoBySpecIds(specIds,goods.getShopId());
//        if (prodSpecInfoDtos == null || prodSpecInfoDtos.size() == 0) {
//            log.error("--- pmcFeignApi.getSpecBySpecName(prodSpecInfoDto)内部异常，参数：{} ---", prodSpecInfoDtos);
//            throw new PmcBizException(ErrorCodeEnum.GL99990002);
//        }

        return prodSpecInfoDtos;
    }
}
